//
//  ThumbnailTableViewCell.m
//  UGoods
//
//  Created by dllo on 16/1/20.
//  Copyright © 2016年 蓝鸥科技.李贺. All rights reserved.
//

#import "ThumbnailTableViewCell.h"
#import "BaseView.h"
#import <UIImageView+WebCache.h>
#import "ConstantsDefine.h"
@interface ThumbnailTableViewCell ()

@property (nonatomic, retain) BaseView *backView;


@end

@implementation ThumbnailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backView = [[BaseView alloc] init];
        [self.contentView addSubview:_backView];
        [_backView release];
        
        self.thumbnailImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_thumbnailImageView];
        [_thumbnailImageView release];
    }
    return self;
}

// 自适应图片高度
+ (CGFloat)heigthWithImageWidth:(CGFloat)width height:(CGFloat)height {
    if (width != 0) {
        CGFloat scale = width / 355 * WIDTH;
        CGFloat realHeight = height / scale;
        return realHeight;
    } else {
        return 0;
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _backView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    
    CGFloat h = [[self class] heigthWithImageWidth:self.width height:self.height];
    _thumbnailImageView.frame = CGRectMake(10 * WIDTH, 10 * HEIGHT, self.contentView.frame.size.width - 20 * WIDTH, h * HEIGHT);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
